
from django.db import transaction
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.views import APIView

from py_web.common.auth.MyAuth import MyAuth
from py_web.common.db.BaseModelViewSet import BaseModelViewSet
from py_web.security.SecuritySerialization import RoleMenuSerializer
from py_web.security.models import RoleMenu
from py_web.user.views.views import SaveOrUpdateRole

# 角色菜单关联表
class RoleMenuView(MyAuth, BaseModelViewSet):
    queryset = RoleMenu.objects.all()
    serializer_class = RoleMenuSerializer

# 新增角色和角色选择的菜单信息
class SaveRoleMenu(MyAuth, APIView):
    @transaction.atomic
    def post(self, request: Request, *args, **kwargs) -> Response:
        return SaveOrUpdateRole(request, "S")